package cn.zust.edu;

import cn.zust.edu.dao.UserDao;
import cn.zust.edu.dao.UserJpaDao;
import cn.zust.edu.dao.UserMapper;
import cn.zust.edu.entity.UserEntity;
import cn.zust.edu.model.UserModel;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws IOException {
        //1-JPA test
//        ApplicationContext ac=new ClassPathXmlApplicationContext("beans.xml");
////        UserDao userDao=ac.getBean("userDao", UserDao.class);
//        UserJpaDao userJpaDao=ac.getBean("userJpaDao",UserJpaDao.class);
//        List<UserEntity> userList=userJpaDao.findByOodId();
//
//        System.out.println(userList.size());

        //2-MyBatis test

//        InputStream in = Resources.getResourceAsStream("mybatis-conf.xml");;
//        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
//        SqlSession session =factory.openSession();
//        UserMapper userMapper =session.getMapper(UserMapper.class);
//        UserModel user=userMapper.getUserById(5);
//        System.out.println(user.getName());

        //3-mybatis-spring test
        ApplicationContext ac=new ClassPathXmlApplicationContext("beans.xml");
        UserMapper userMapper=ac.getBean("userMapper",UserMapper.class);
        UserModel user=userMapper.getUserById(5);
        System.out.println(user.getName());
    }
}
